| Conditions | 6 |
| Total Lines | 56 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import * as core from '@actions/core'; |
||
| 62 | |||
| 63 | async function processSummary({ |
||
| 64 | GH_TOKEN, |
||
| 65 | WAKATIME_BASE_URL, |
||
| 66 | WAKA_API_KEY, |
||
| 67 | GIST_ID, |
||
| 68 | MAX_RESULT, |
||
| 69 | DATE_RANGE, |
||
| 70 | PRINT_SUMMARY, |
||
| 71 | USE_OLD_FORMAT |
||
| 72 | }) { |
||
| 73 | const httpClient = new HttpClient('WakaTime-Gist/1.3 +https://github.com/marketplace/actions/wakatime-gist'); |
||
| 74 | const languages = await fetchStatistics(httpClient, WAKATIME_BASE_URL, DATE_RANGE, WAKA_API_KEY); |
||
| 75 | if (!languages) { |
||
| 76 | core.setFailed('Action failed: empty response from wakatime.com'); |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | const updateDate = new Date().toLocaleDateString('en-us', {day: 'numeric', year: 'numeric', month: 'short'}); |
||
| 80 | const title = generateTitle(DATE_RANGE, updateDate); |
||
| 81 | const summaryTable: any[] = createSummaryTable(); |
||
| 82 | summaryTable.push(['Statistics received', '✔']); |
||
| 83 | const lines = generateLanguageSummary(languages, MAX_RESULT, USE_OLD_FORMAT); |
||
| 84 | if (lines.length === 0) { |
||
| 85 | core.notice('No statistics for the last time period. Gist not updated'); |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | const octokit = new Octokit({auth: GH_TOKEN}); |
||
| 89 | const gist = await octokit.gists.get({gist_id: GIST_ID}).catch(error => { |
||
| 90 | core.setFailed('Action failed: Gist ' + error.message); |
||
| 91 | return null; |
||
| 92 | }); |
||
| 93 | if (!gist) return; |
||
| 94 | const filename = Object.keys(gist.data.files || {})[0]; |
||
| 95 | if (!filename) { |
||
| 96 | core.setFailed('Action failed: Gist filename not found'); |
||
| 97 | return; |
||
| 98 | } |
||
| 99 | await octokit.gists.update({ |
||
| 100 | gist_id: GIST_ID, |
||
| 101 | files: { |
||
| 102 | [filename]: { |
||
| 103 | filename: title, |
||
| 104 | content: lines.join('\n'), |
||
| 105 | }, |
||
| 106 | }, |
||
| 107 | }).catch(error => core.setFailed('Action failed: Gist ' + error.message)); |
||
| 108 | summaryTable.push(['Gist updated', '✔']); |
||
| 109 | const summary = core.summary |
||
| 110 | .addHeading('Results') |
||
| 111 | .addTable(summaryTable) |
||
| 112 | .addBreak() |
||
| 113 | .addLink('WakaTime-Gist/2.0', 'https://github.com/marketplace/actions/wakatime-gist'); |
||
| 114 | if (PRINT_SUMMARY) { |
||
| 115 | await summary.write(); |
||
| 116 | } else { |
||
| 117 | console.log(summary.stringify()); |
||
| 118 | } |
||
| 125 |